package cn.daniellee.plugin.component;

import cn.daniellee.plugin.OnlineRewards;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.List;

public class RewardSender extends BukkitRunnable {


	@Override
	public void run() {
		String command = (String) OnlineRewards.config.get("reward-command");
		List<Player> players = (List<Player>) Bukkit.getOnlinePlayers();
		for (Player player : players) {
			if (!player.isOp()) {
				String target = command;
				if (command.contains("%p%")) target = command.replace("%p%", player.getName());
				Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), target);
				player.sendMessage(OnlineRewards.PREFIX + OnlineRewards.config.get("reward-sent"));
			}
		}
	}
}
